<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head> 
   <meta charset="UTF-8">
   <%@ include file="/WEB-INF/views/include/head.jsp"%>
   <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
   <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
   <script src="${ctxStatic}/js/jquery-1.9.1.min.js"></script>
   <script src="${ctxStatic}/js/layer.js"></script>
   <script src="${ctxStatic}/js/style.js"></script>
   <script src="${ctxStatic}/jquery-barcode/jquery-barcode.js" type="text/javascript"></script>
   
    <script type="text/javascript">
 // 下拉选框带搜索功能
    $(document).ready(function() {
    	$("#procategory").select2();
    	$("#category").select2();
    	$("#venderId").select2();
    	$("#brandId").select2();
    	if ($("#id").val()!=""&&$("#id").val()!=null) {
			$("#procategory").attr("disabled",true);
			$("#category").attr("disabled",true);
		}
    	searchListForm();
    });
    
 // 删除子项目
     function deleteCurrentRow(obj,id){ 		 
 		 if (confirm("<spring:message code="company_edit_areYouSure"/>")) {
            $.post("${ctx}/produce/technology/deleteSave?id="+id,"",function(result){
            	var saveFlg = result["saveFlg"];
            	if (saveFlg == "true") {
		            var tr=obj.parentNode.parentNode;  
		            var tbody=tr.parentNode;  
		            tbody.removeChild(tr);  
		            tipParent("删除成功");
            	}else{
					tipParent("删除失败");
            	}
        	},'json');
		}
	 }
    
    function addBankCheck(obj){
    	/* 获取当前行的值 */		
	    var tr = obj.parentNode.parentNode;
		var index = tr.rowIndex;
	    var name = $(tr).find('input#name')[0].defaultValue;	    
	    var instructions = $(tr).find('input#instructions')[0].defaultValue;
	    var jbren = $(tr).find('input#jbren')[0].defaultValue;
	    var createTime = $(tr).find('input#createTime')[0].defaultValue;
	    var state = $(tr).find('input#state')[0].defaultValue;
		popup('900px','484px','${ctx}/produce/technology/add?name='+name+'&instructions='+instructions+'&jbren='+jbren
				+'&createTime='+createTime+'&state='+state+'&index='+index);    	    	
    }
    
     
    /* 保存编辑信息 */
    function editSaveForm(){
    	$('.showHtml').find('input,select').attr('disabled',false);
    	$('#procategory').attr('disabled',false);   	
    	var params = $("#inputForm").serialize();
    	$.post("${ctx}/produce/technology/editComSave",params,function(result){
    		/* 弹出提示框,刷新父页面,关闭当前页面 */
    		tipParent(result.message);
    		 window.parent.frames[0].searchListForm();
    	closeWin();    		 	
    	},'json');
    }
	
	// 客户联动
	function venderSelFun(t){				
		if($("#venderId").val() != '' && $("#venderId").val() != null && $("#venderId").val() != "undefined"){
			// 创建
			var vId = $('#id').val();
			if(vId == null || vId == '' || vId == "undefined"){
				var simpleName=$(t).find("option:selected").attr("data-value");
				if(simpleName!=null && simpleName!=''){
					simpleName = simpleName.toUpperCase();
				}				
			}	
			
			// 客户品牌联动
			var param = '';
			var paramVenderId = $("#venderId").val();
			param={"venderId":paramVenderId};
	        $.post("${ctx}/inventory/request/brand",param,function(result){            
	            var html="<option value=''><spring:message code="customer_pleaseChoose"/></option>";
	            $.each(result,function(i,e){
	                html+="<option value='"+e.brandId+"'>"+e.brandName+"</option>";
	            });
	            $("#brandId").html(html);
	            $("#brandId").select2();
	        },'json');
		}else{			
			var htmlEmpty="<option value=''><spring:message code="customer_pleaseChoose"/></option>";
            $("#brandId").html(htmlEmpty);
            $("#brandId").select2();
		}
		
		delAllDetails();
	}
    
   function checkBtn(){
	var procategory = $("#procategory").val();
	if (procategory != "PROCESS_CATEGORY-normal") {
	   var procategory = $("#procategory").val();
	   var category = $("#category").val();
	   var venderId = $("#venderId").val();
	   var venderName = $("#venderId").find("option:selected").text();
	   var brandId = $("#brandId").val();
	   var brandName = $("#brandId").find("option:selected").text();
	   if (brandId=="") {
		   brandName="";
		}
	   if (procategory==""||category==""||venderId=="") {
			alert("请选择工艺类别、款式类别和客户");
			return;
	   }
	   popup('900px','484px','${ctx}/produce/technology/add?procategory='+procategory+'&category='+category+'&venderId='+venderId+'&brandId='+brandId+'&ognizationName='+venderName+'&brandName='+brandName);
	}else{
		var procategory = $("#procategory").val();
		   var category = $("#category").val();
		   if (procategory==""||category=="") {
				alert("请选择工艺类别和款式类别");
				return;
		   }
		   popup('900px','484px','${ctx}/produce/technology/add?procategory='+procategory+'&category='+category);
	}
   }
   function showOrHide(){
	   var procategory = $("#procategory").val();
	   if (procategory == "PROCESS_CATEGORY-normal") {
		   $("#venderBrand").hide();
	   }else {
		   $("#venderBrand").show();
	   }
   }
   
   function popupEdit(t,term){
	   var trObj = t.parentNode.parentNode;
	   var trIndex =  trObj.rowIndex;
	   popup('900px','484px','${ctx}/produce/technology/updateMessages?'+term+'&index='+trIndex);
   }
    </script> 
</head>
<body>
<form id="inputForm" name="inputForm">
<!-- 编辑头部 -->   
<div id="createHead" class="layerHeader clearfix">
	<p class="headerTitle"><spring:message code="production_process_create"/></p>
	<c:choose>
	   <c:when test="${process.id!=null && process.id!=''}">
	    <!-- 编辑 --> 
			<p class="headerTitle"><spring:message code="company_edit_edit"/></p>
       </c:when>       
    </c:choose>
    <div class="headerButton clearfix">
       <%--  <!-- 确认 -->      
       	<button type="button" onclick="editSaveForm()"><spring:message code="company_edit_ok"/></button> --%>
        <!-- 取消 -->
        <button type="button" onclick="closeWin()"><spring:message code="company_edit_cancle"/></button>
    </div>    
</div>
<!-- 确认画面头部 -->
<div id="okHead" class="layerHeader clearfix" style="display: none;">	      
             <p class="headerTitle"><spring:message code="company_edit_ok" /></p>    
    <div class="headerButton clearfix">
    <shiro:hasPermission name="mycompany:message:edit">
    	<c:choose>
	  	 	<c:when test="${process.id!=null && process.id!=''}">
	  	 	 <!-- 编辑 保存 --> 
				<button type="button" onclick="editSaveForm()"><spring:message code="common_save" /></button>
      		 </c:when>
      		 <c:otherwise>
      	 	 <!-- 创建 保存 --> 
       	   		<button type="button" onclick="editSaveForm()"><spring:message code="common_save" /></button>
     	 	 </c:otherwise>
    	 </c:choose>
     </shiro:hasPermission>         
        <!-- 取消 -->
          <button type="button" onclick="closeWin()"><spring:message code="company_edit_cancle"/></button>
    </div>
</div>

<div id="showHtml" class="tabBoxSm" >
<div class="tabSm smOrderBox" style="padding: 10px;">
	 <div class="clearfix" style="padding-left: 20px;">
	 <input type="hidden" id="createTime" name="createTime" value="${fns:getDate('yyyy-MM-dd')}">
	 <input type="hidden" id="id" name="id" value="${process.processList[0].id }"/>
	 	<div class="">        	
        		<div class="col-50 items clearfix haveToBox">
        		<!-- 工艺类别 -->            		
          			<p class="tit"><spring:message code="production_process_category"/></p>
          			<c:set value="<%=ResourcesUtil.getConfig(\"process_category\")%>" var="procategory"/>
                   <select style="width:200px" id="procategory" name="procategory" onchange="showOrHide();">
                            <option value=""><spring:message code="contract_edit_please"/></option>
	                       <c:forEach items="${fns:getDictList(procategory)}"   var="procategoryInfo">
	                            <option data-value="${procategoryInfo.itemValue}" value="${procategoryInfo.itemCode}-${procategoryInfo.itemValue}" 
	                            <c:if test="${fn:split(process.procategory,'-')[1] eq procategoryInfo.itemValue }">selected="selected"</c:if>> 
	                                ${procategoryInfo.itemName}
	                            </option>
	                       </c:forEach>
	               </select>    
        		</div>        
        		<div class="col-50 items clearfix haveToBox">
        		<!-- 款式类别 -->
            		<p class="tit"><spring:message code="production_process_style_category"/></p>
            		<c:set value="<%=ResourcesUtil.getConfig(\"style_category\")%>" var="category"/>
                   <select style="width:200px" id="category" name="category">
                            <option value=""><spring:message code="contract_edit_please"/></option>
	                       <c:forEach items="${fns:getDictList(category)}"   var="category">
	                            <option data-value="${category.itemValue}" value="${category.itemCode}-${category.itemValue}" 
	                            <c:if test="${fn:split(process.category,'-')[1] eq category.itemValue }">selected="selected"</c:if>> 
	                                ${category.itemName}
	                            </option>
	                       </c:forEach>
	               </select>        
        		</div>        
    	</div>
    	<c:if test="${process.procategory != 'PROCESS_CATEGORY-normal' }">
    <div class="" id="venderBrand">
        		<div class="col-50 items clearfix haveToBox">
        		<!-- 客户 -->
            		<p class="tit"><spring:message code="production_process_customer"/></p>
            		<c:set  var="ognizationName"/>
          			<select style="width:200px" id="venderId" name="venderId"  onchange="venderSelFun(this);">
                            <option value=""><spring:message code="contract_edit_please"/></option>
	                       <c:forEach items="${process.venderList}" var="venderInfo">
	                            <option data-value="${venderInfo.ognizationSimpleName}" 
	                            <c:if test="${process.venderId eq venderInfo.id}">selected="selected"</c:if> value="${venderInfo.id}" > 
	                                ${venderInfo.ognizationName}
	                            </option>
	                       </c:forEach>
	               </select>       
          			
        		</div>        
        		<div class="col-50 items clearfix haveToBox">
        		<!-- 品牌  -->
            		<p class="tit"><spring:message code="production_process_brand"/></p>
            		<c:set var="brandName"/>               
                	<select style="width:200px" id="brandId" name="brandId" onchange="delAllDetails();">
                            <option value=""><spring:message code="contract_edit_please"/></option>
	                       <c:forEach items="${process.brandList}"   var="brandInfo">
	                            <option <c:if test="${process.brandId eq brandInfo.brandId}" >selected="selected"</c:if> value="${brandInfo.brandId}"> 
	                                ${brandInfo.brandName}
	                            </option>
	                       </c:forEach>
	               </select>           
        		</div>        
    </div>
    </c:if>
        <div class="" style="height: 40px;">
				<div style="float: left;">
					<!-- 生产工艺  -->
					<p class="tit"><spring:message code="production_process_process"/>							
					<button id="operateP" type="button" onclick="checkBtn();"><spring:message code="dict_chooseAdd"/></button></p>		
				
				</div>
				<div style="float: right;"> 
				</div>
		</div>
</div> 
	  <div class="tableArea"> 	              	
		<div class="tableScrollSm" style="overflow: auto;height: 470px;width: 977px;">
		        	<table cellpadding="0" class="tableHead">		                    
		                  <tr>
		                  		<th><p class="tab-cz" style="width: 100px"><spring:message code="production_process_delete" /></p></th>
				                <th><p class="tab-mc" style="width: 100px"><spring:message code="production_process_name" /></p></th>
				                <th><p class="tab-tp" style="width: 100px"><spring:message code="production_process_picture" /></p></th>
				                <th><p class="tab-zt" style="width: 100px">客户</p></th>
				                <th><p class="tab-zt" style="width: 100px">品牌</p></th>
				                <th><p class="tab-xq" style="width: 150px"><spring:message code="production_process_instructions" /></p></th>
				                <th><p class="tab-zt" style="width: 100px"><spring:message code="production_process_state" /></p></th>
				                <th><p class="tab-cjr" style="width: 100px"><spring:message code="production_process_founder" /></p></th>
				                <th><p class="tab-cjrq" style="width: 100px"><spring:message code="production_process_create_date" /></p></th>
		                  </tr>		                    
		            </table>		                 		            		        
                    <table cellpadding="0" class="tablebody" name ="perantTable" id ="perantTable" >
                    <tbody >
                     <tr class = "none">
                        <td style="width: 101px"><img src="${ctxStatic}/images/btn-bj.png" onclick='addBankCheck(this);' height="30" width="30">&nbsp;&nbsp;
                        <img src="${ctxStatic}/images/btn-sc.png" height="30" width="30"  onclick='deleteCurrentRow(this);'></td>
                        <td style="width: 101px"></td>
                        <td style="width: 101px"></td>
                        <td style="width: 101px"></td>
                        <td style="width: 101px"></td>
                        <td style="width: 151px"></td>                       
                        <td style="width: 101px"></td>
                        <td style="width: 101px"></td>
                        <td style="width: 101px"></td>                            
                        <td class = "none"></td>
                   </tr>
                    <c:forEach items="${process.processList}" var="processInfo" varStatus="status">
                    <tr>
                        <td style="width: 101px"><img src="${ctxStatic}/images/btn-bj.png" onclick="popupEdit(this,'id=${processInfo.id}&name=${processInfo.name}&nameImagePath=${processInfo.nameImagePath}&instructions=${processInfo.instructions}&state=${processInfo.state}');" height="30" width="30">&nbsp;&nbsp;
                        <img src="${ctxStatic}/images/btn-sc.png" height="30" width="30"  onclick="deleteCurrentRow(this,${processInfo.id});"></td>
                        <td style="width: 101px">${processInfo.name}</td>
                        <td style="width: 101px">
		                  <c:if test="${not empty processInfo.nameImagePath}">
		                        <img src="${processInfo.nameImagePath}" style="width: 50px">
		                  </c:if>
		                  <c:if test="${empty processInfo.nameImagePath}">
		                        <img src="${ctxStatic}/images/pic-none.jpg" style="width: 50px">
		                  </c:if>
		                </td>
		                <td style="width: 101px;" class="tab-zt">${processInfo.ognizationName }</td>
		                <td style="width: 101px;" class="tab-zt">${processInfo.brandName }</td>
                        <td style="width: 151px">${processInfo.instructions}</td>                       
                        <c:if test="${processInfo.state == 1}">
                        <td style="width: 101px">启用</td>
                        </c:if>   
                        <c:if test="${processInfo.state == 0}">
                        <td style="width: 101px">停用</td>
                        </c:if> 
                        <td style="width: 101px">${processInfo.jbren}</td>
                        <td style="width: 101px"><fmt:formatDate value="${processInfo.createTime}" pattern="yyyy-MM-dd" /></td>                            
                        <input type="hidden" name="processList[${status.index}].name" value="${processInfo.name}">
                        <input type="hidden" name="processList[${status.index}].nameImagePath" value="${processInfo.nameImagePath }">
                        <input type="hidden" name="processList[${status.index}].instructions" value="${processInfo.instructions }">
                        <input type="hidden" name="processList[${status.index}].state" value="${processInfo.state }">
                        <input type="hidden" name="processList[${status.index}].jbren" value="${processInfo.jbren }">
                        <input type="hidden" name="processList[${status.index}].createTime" value="${processInfo.createTime }">
                   </tr>
                    </c:forEach>
                	</tbody>
                </table>
                <div id="hiddenHtml"></div>
		</div>
	  </div>		
	</div>
</div>	
</form>	
</body>
</html>